package com.itheima.controller;

import com.itheima.common.VodTemplate;
import com.itheima.domain.Movie;
import com.itheima.service.MovieService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 查询指定分类接口
 * @Author: hsp
 * @Date: 2022/11/18-11-18-10:26
 * @Description: com.itheima.controller
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/portal/movie")
public class MovieController {

    @Resource
    private MovieService movieService;

    @Resource
    private VodTemplate vodTemplate;

    //根据栏目对应标识查询指定的视频列表
    //1. 主键查询   2. 条件查询
    @GetMapping("/findByCid")
    public List<Movie> findByCid(Integer cid){
        return movieService.findByCid(cid);
    }

    //根据id查询视频信息
    @GetMapping("/findById")
    public Movie findById(Integer id) throws Exception {

        //1. 根据id查询影视信息
        Movie movie = movieService.findById(id);

        //2. 根据playId从阿里获取播放秘钥
        //校验影视信息
        String playAuth = vodTemplate.getVideoPlayAuth(movie.getPlayId()).getPlayAuth();
        movie.setPlayAuth(playAuth);

        //3. 返回影视对象
        return movie;
    }



}
